#ifndef _DRNE_List_H_
#define _DRNE_List_H_

#include <time.h>
#include "link_list.h"

#ifndef DRNE_DEBUG_EN
	//#define DRNE_DEBUG_EN					// FIXME, debug
#endif

/*
 * valid frame_no [curr - DRNE_FRMNO_LIMIT, curr + DRNE_FRMNO_LIMIT]
 */
#ifndef DRNE_FRMNO_LIMIT
	#define DRNE_FRMNO_LIMIT		2000
#endif

/*
 * default frame record age time
 */
#ifndef DRNE_TIMER_AGE
	#define DRNE_TIMER_AGE			60		// 60 seconds, delete timeout data
#endif

/*
 * frame record table size, default is [64 * 256] ip addr
 */
#define DRNE_MAX_NET_NUM			64		// FIXME
	#define DRNE_MAX_SN_NODE_NUM	256


/******************************************************************
 * frame record struct
 ******************************************************************/
typedef struct _t_drne_net
{
	unsigned int			subnet;

	struct
	{
		unsigned char		used;

		unsigned int		port;
		unsigned short		frmno;

		time_t				timer;
	}	inf[DRNE_MAX_SN_NODE_NUM];
}	t_drne_net;


/******************************************************************
 * frame record class 
 ******************************************************************/
class drne_list
{
public:
	drne_list( int max = DRNE_MAX_NET_NUM );
	~drne_list(void);

	void 						free	( void );
	void						tick	( void );

	int							insert	( unsigned int addr, unsigned int port, unsigned short frmno );

	unsigned int				dstport	( unsigned int addr );

	void 						set_age	( unsigned short age )		{ m_age = age; }

	void 						remove	( unsigned int addr );

	void						show	( void );	// debug, need DRNE_DEBUG_EN

private:
	list_node<t_drne_net> * 	get		( unsigned int addr );

protected:
	const unsigned short		m_max;

	unsigned short				m_age;
	time_t						m_timer;

	link_list<t_drne_net>		m_lst;
};

#endif
